
import React, { Component } from 'react';
import {getDeviceId, setDocumentTitle} from '../utils'
import HomeAlbumList from '../components/HomeAlbumList'

class CategoryAlbums extends Component {

    constructor(props, context) {
        super(props, context);
        this.albumItemClick = this.albumItemClick.bind(this);

        let groupName = this.props.location.group_name;
        if (groupName) {
            localStorage.setItem('group_name',groupName);
        }else {
            groupName = localStorage.getItem('group_name') || '';
        }

        let groupId = this.props.location.groupId;
        if (groupId) {
            sessionStorage.setItem('groupId',groupId);
        }else {
            groupId = parseInt(sessionStorage.getItem('groupId'),10);
        }
        this.state = {
            groupId:groupId,
            groupName:groupName
        };
    }

    componentDidMount() {
        setDocumentTitle(this.state.groupName);
    }


	albumItemClick(album) {
		this.props.history.push({
			pathname: '/album',
			device_id: getDeviceId(),
			album: album
		});
	}

    render() {
        return (
            <div>
                <HomeAlbumList
                    groupId={this.state.groupId}
                    albumItemClick={this.albumItemClick}>
                </HomeAlbumList>
            </div>
        );
    }
}


export default CategoryAlbums;